﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace DanielVaughan.Logging
{
	public class ClientLoggingException : ApplicationException
	{		
		/// <summary>
		/// Gets or sets the localized user message, that is appropriate 
		/// for displaying to a user.
		/// </summary>
		/// <value>The user message.</value>
		public string UserMessage { get; protected set; }

		/// <summary>
		/// Gets a value indicating whether the UserMessage is <code>null</code>.
		/// </summary>
		/// <value><c>true</c> if the UserMessage is not <code>null</code>; 
		/// otherwise, <c>false</c>.</value>
		public bool UserMessagePresent
		{
			get
			{
				return UserMessage != null;
			}
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ClientLoggingException"/> class.
		/// </summary>
		/// <param name="userMessage">The localized user message that is appropriate 
		/// for displaying to a user. Can be <code>null</code>.</param>
		/// <param name="developerMessage">The developer message that may contain 
		/// detailed information regarding the exception.</param>
		public ClientLoggingException(string developerMessage, string userMessage) 
			: base(developerMessage)
		{
			UserMessage = userMessage;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ClientLoggingException"/> class.
		/// </summary>
		/// <param name="userMessage">The localized user message that is appropriate 
		/// for displaying to a user. Can be <code>null</code>.</param>
		/// <param name="developerMessage">The developer message that may contain 
		/// detailed information regarding the exception.</param>
		/// <param name="innerException">The inner exception.</param>
		public ClientLoggingException(string developerMessage, string userMessage, Exception innerException)
			: base(developerMessage, innerException)
		{
			UserMessage = userMessage;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ClientLoggingException"/> class.
		/// </summary>
		/// <param name="developerMessage">The developer message that may contain 
		/// detailed information regarding the exception.</param>
		public ClientLoggingException(string developerMessage) : base(developerMessage)
		{
			/* Intentionally left blank. */
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="ClientLoggingException"/> class.
		/// </summary>
		/// <param name="developerMessage">The developer message that may contain 
		/// detailed information regarding the exception.</param>
		/// <param name="innerException">The inner exception.</param>
		public ClientLoggingException(string developerMessage, Exception innerException)
			: base(developerMessage, innerException)
		{
			/* Intentionally left blank. */
		}

		public ClientLoggingException(SerializationInfo info, StreamingContext context) :
            base(info, context)
		{
			UserMessage = info.GetString("UserMessage");
		}

		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("UserMessage", UserMessage);
			base.GetObjectData(info, context);
		}
	}
}
